
<script>

    export default {
        data(){
          return{
              tablePage: {
                  pageNum: 1,
                  pageSize: 10,
                  total: 0
              },
              tableSelection: [],
              tableSearch: {},
              tableList: [],
          }
        },
        methods:{

            changeSelection(selection) {
                this.tableSelection = selection
            },
            clickSearch(){
                this.updateList()
            },
            clickCreate(){
                this.$refs['dialog'].open()
            },
            clickEdit(row){
                this.$refs['dialog'].open(row)
            },
            clickPreview(row){
                this.$refs['preview'].openSingle(row)
            },
            clickBatchDelete(data){
                let ids = []
                let name = ''
                if(Array.isArray(data)){
                    for(let item of this.tableSelection){
                        ids.push(item.id)
                    }
                }else{
                    ids.push(data.id)
                    name = data.name
                }

                DeleteAlert(this,name).then(()=>{
                    removeAdConfig({ids:ids}).then(res => {
                        if (res.code === 0) {
                            this.updateList()
                        }
                    });
                })
            },
            updateList(){
                let search = Object.assign({},this.tableSearch,this.tablePage)


                listAdConfig(search).then(res => {
                    if (res.code === 0) {
                        if (res.data.data.length !== 0) {
                            this.tableList = res.data.data;
                        } else {
                            this.tableList = [];
                        }
                        this.tablePage.total = res.data.recordsTotal;
                    } else {
                        this.$Message.warning(res.message || res.errorMessage);
                    }
                })
            }
        },mounted() {
            this.updateList()
        }
    }
</script>
